define(function(require,exports,module){

	//检测类
	var Auth = require('qd-auth-1.0');

	$("#J_cash").attr("action","/member/cash/doCash.html");




//表单验证
	require.async('/plugins/jquery-validation-1.13.0/jquery.validate', function () {
		require.async('/plugins/jquery-validation-1.13.0/additional-methods', function () {
			//-S-手机号码验证
			jQuery.validator.addMethod("maxAmount", function(value, element){
				var value = parseInt(value);
				var max_amount = parseInt($('#cash_single_max_amount_limit').val());
				if (max_amount) {
					if (value > max_amount) {
						return false;
					} else {
						return true;
					}
				} else {
					return true;
				}
			}, "最高金额不得高于于"+$('#cash_single_max_amount_limit').val()+"元");
			//-E-手机号码验证
			// -S-手机号码验证
			jQuery.validator.addMethod("minAmount", function(value, element){
				var value = parseInt(value);
				var typeAccount = parseInt($('#userNature').val());
				var min_amount = (typeAccount == 1)?parseInt($('#cash_single_min_amount_limit').val()):parseInt($('#comp_cash_single_max_amount_limit').val());
				if (min_amount) {
					if (value < min_amount) {
						return false;
					} else {
						return true;
					}
				} else {
					return true;
				}
			}, "最低金额不得低于"+((parseInt($('#userNature').val()) == 1)?parseInt($('#cash_single_min_amount_limit').val()):parseInt($('#comp_cash_single_max_amount_limit').val()))+"元");
			//-E-手机号码验证
// -S-手机号码验证
			jQuery.validator.addMethod("userMoney", function (value, element) {
				var value = parseInt(value);
				var rest = parseInt($('#user_rest_money').val());
				if (rest) {
					if (value <= rest) {
						return true;
					} else {
						return false;
					}
				} else {
					return false;
				}
			}, "最高金额不得高于" + parseInt($('#user_rest_money').val())+ "元");
//-E-手机号码验证
			var rulesVaild = ["money","payPwd"];
			$("#getCash").validate({
				rules: {
					money: {
						required: true,
						maxAmount: true,
						minAmount: true,
                        userMoney:true,
					},
					payPwd: {
						required: true,
					}
				},
				messages: {
					money: {
						required: "不能为空",
						//maxAmount: "最高金额不得低于" + max_amount + "元",
						//minAmount: "最低金额不得低于" + min_amount + "元",
					},
					payPwd: {
						required: "支付密码不能为空",

					},
				},

				showErrors: function (errorMap, errorList) {

					//$("#showErrorTip").css("display","none");
					$("#showErrorTip2").text("");

					for (var i = 0, len = rulesVaild.length; i < len; i++) {
						if (errorMap[rulesVaild[i]] != undefined) {
							//$("#showErrorTip").css("display","block");
							$("#showErrorTip2").text(errorMap[rulesVaild[i]]);
						}
					}

				},
			});

		})
	})




	//判断是否已认证
	$.ajax({
		url:"/member/useridentify/realNameStatus.html?randomTime=" + (new Date()).getTime(),
		type:"get",
		dataType:"json",
		success:function(data){
			require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
				if(data.result==false){
						$.layer({
							type: 1,
							closeBtn: false,
			                title: "&nbsp;",
						    area: ['450px', '190px'],
						    border: [1, 1, '#cecfd0'],
						    page: {
						        html: '<div class="tipsWrap w450"><div class="tipsTxt"><i class="iconfont tipIco">&#xe63c;</i><span>您尚未通过实名认证，请先认证。</span></div><div class="tipsBtnBar"><a href="/member/security/setting.html" class="okBtn">马上去认证</a></div></div>'
						    }
						});
				}
			});
		}
	})

	require.async('radio',function(){
		$('.cashCardList input[type="radio"]').minRadio({
			checkedClass:"bank_radio_hover",
			Element:"bank_radio",
			showTxt:true
		});
	});

	require.async("/plugins/jquery-validation-1.13.0/jquery.validate",function(){
		require.async("/plugins/jquery-validation-1.13.0/additional-methods",function(){
			$("#J_cash").validate({
				rules: {
					money: {
						required: true,
						max:parseFloat($("#available_Balance").text().replace(/[^\d]/g,'')),
						min:0.01
					},
					payPwd:{
						required:true
					}
				},
				messages:{
					money: {
						required: "请输入提现金额" ,
						max:"提现金额不能大于您的可用余额",
						min:"不能小于0.01元"
					},
					payPwd:{
						required: "请输入交易密码",
					}
				},
				errorElement:"em",
				errorPlacement:function(error,element){
					error.appendTo(element.parent().find("span"));
				},
				submitHandler:function(form){
					require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
						require.async('jquery.form',function(){
							$(form).ajaxSubmit({
		    					dataType:'json',
		    					success:function(data){

									//单点登录检测
									if(Auth.checkLogin(arguments[0]) == false) {return ;}

						        	if(data.result==true){
						        		$.layer({
											type: 1,
											closeBtn: [0,true],
							                title: "&nbsp;",
										    area: ['450px', '190px'],
										    border: [1, 1, '#cecfd0'],
										    page: {
										        html: '<div class="tipsWrap w450"><div class="tipsTxt"><i class="iconfont tipIco">&#xe63c;</i><span>提现申请成功，等待系统审核！</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn">确认</a></div></div>'
										    }
										});
										$(".okBtn").click(function(){
											window.location.href = "/member/cash/log.html";
										});
										$(".xubox_close").click(function(){
											window.location.reload();
										});

						        	}else{
						        		$.layer({
											type: 1,
										    closeBtn: [0,true],
							                title: "&nbsp;",
										    area: ['384px', '186px'],
										    border: [1, 1, '#cecfd0'],
										    page: {
										        html: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn failBtn">确定</a></div></div>'
										    },
										    close: function(index){
										    	layer.closeAll();
										    }
										});
										$(".failBtn").click(function(){
											layer.closeAll();
										});
						        	}
		    					}
		    				});
						 })
				});
			  }
		});
		});
	});

	//解决充值密码记住问题
	/*$('.cashMoneyText').focus(function() {
		$('.cashMoneyText').hide();
		$('.cashMoney').show().val('').focus();
	});*/

});